/**
 * 
 */
package com.yuchen.lucene;

import org.apache.lucene.search.Query;
import org.junit.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 测试索引过程
 * @author Winter Lau
 */
public class LuceneHelperTester {


	@Test
	public void  add() throws IOException {
		LuceneHelper helper = LuceneHelper.init("D:\\TEST");
		List<Post> posts = new ArrayList<Post>();
		for(int i=0;i<10;i++){
			Post post = new Post();
			post.setId(i);
			post.setTitle("测试标题——"+i);
			post.setBody("测试内容hello world --"+i);
			if(i==1){
				Map<String, String> extendIndexes = new HashMap<String, String>(2);
				extendIndexes.put("url","www.baidu.com");
				extendIndexes.put("version","1.0.0");
				post.setExtendIndexes(extendIndexes);
			}
			posts.add(post);
		}
		helper.add(posts);
	}

	@Test
	public void query() throws IOException {
		LuceneHelper helper = LuceneHelper.init("D:\\TEST");
		Query query = SearchHelper.makeQuery("body","测试 内容 hello",1);
		List<Long> ids = helper.find(Post.class,query,null,null,1,20);
		for(Long id : ids){
			System.out.println(id.toString());
		}
	}


}
